<?php defined('In33hao') or exit('Access Invalid!');?>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back" href="index.php?act=hao&op=diymenu" title="返回微信菜单"><i class="fa fa-arrow-circle-o-left"></i></a>
            <div class="subject">
                <h3><?php echo $lang['diymenu'];?> - 编辑微信菜单</h3>
                <h5>你可以在这里编辑微信菜单</h5>
            </div>
        </div>
    </div>
    <form id="diymenu_form" enctype="multipart/form-data" method="post">
        <input type="hidden" name="form_submit" value="ok" />
        <input type="hidden" name="id" id="id" value="<?php echo $output['res']['id'];?>" />
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label for="title"><em>*</em>菜单名称</label>
                </dt>
                <dd class="opt">
                    <input type="text" value="<?php echo $output['res']['title'];?>" name="title" id="title" maxlength="20" class="input-txt">
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="url">url链接</label>
                </dt>
                <dd class="opt">
                    <input type="text" value="<?php echo $output['res']['url'];?>" name="url" id="url" maxlength="255" class="input-txt">
                    <span class="err"></span>
                    <p>
                        从功能库选择：
                        <select name="fun" id="fun">
                            <option value="">自定义链接</option>
                            <?php if(!empty($output['module']) && is_array($output['module'])){ ?>
                                <?php foreach($output['module'] as $k => $v){ ?>
                                    <option  value="<?php echo $v['url'];?>"><?php echo $v['title'];?></option>
                                <?php } ?>
                            <?php } ?>
                        </select>
                    </p>
                    <p class="notic">必须是以http://打头的完整链接</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="keyword">关键字</label>
                </dt>
                <dd class="opt">
                    <input type="text" value="<?php echo $output['res']['keyword'];?>" name="keyword" id="keyword" maxlength="20" class="input-txt">
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><?php echo $lang['nc_sort'];?></label>
                </dt>
                <dd class="opt">
                    <input type="text" value="<?php echo $output['res']['sort'];?>" name="sort" id="sort" class="input-txt">
                    <span class="err"></span>
                    <p class="notic">数字范围为0~255，数字越小越靠前</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">显示状态</dt>
                <dd class="opt">
                    <div class="onoff">
                        <label for="brand_recommend1" class="cb-enable <?php if($output['res']['is_show'] == '1'){ ?>selected<?php } ?>"><?php echo $lang['nc_yes'];?></label>
                        <label for="brand_recommend0" class="cb-disable <?php if($output['res']['is_show'] == '0'){ ?>selected<?php } ?>"><?php echo $lang['nc_no'];?></label>
                        <input id="brand_recommend1" name="is_show" <?php if($output['res']['is_show'] == '1'){ ?>checked="checked"<?php } ?>  value="1" type="radio">
                        <input id="brand_recommend0" name="is_show" <?php if($output['res']['is_show'] == '0'){ ?>checked="checked"<?php } ?> value="0" type="radio">
                    </div>
                    <p class="notic"><?php echo $lang['brand_index_recommend_tips'];?></p>
                </dd>
            </dl>
            <div class="bot"><a href="JavaScript:void(0);" class="ncap-btn-big ncap-btn-green" id="submitBtn"><?php echo $lang['nc_submit'];?></a></div>
        </div>
    </form>
</div>
<script src="<?php echo RESOURCE_SITE_URL;?>/js/common_select.js" charset="utf-8"></script>
<script>
    $(function(){
//自动加载滚动条
        $('#type_div').perfectScrollbar();
//按钮先执行验证再提交表单
        $("#submitBtn").click(function(){
            if($("#diymenu_form").valid()){
                $("#diymenu_form").submit();
            }
        });
//表单验证
        $('#diymenu_form').validate({
            errorPlacement: function(error, element){
                var error_td = element.parent('dd').children('span.err');
                error_td.append(error);
            },
            rules : {
                title : {
                    required : true,
                    remote   : {
                        url :'index.php?act=hao&op=diymenu_ajax',
                        type:'get',
                        data:{
                            title : function(){
                                return $('#title').val();
                            },
                            id : function() {
                                return $('#id').val();
                            },
                        }
                    }
                },
                url : {
                    required   : true
                },
                sort : {
                    number   : true
                }
            },
            messages : {
                title : {
                    required : '<i class="fa fa-exclamation-circle"></i>菜单名称必须填写',
                    remote   : '<i class="fa fa-exclamation-circle"></i>该名称已存在'
                },
                url : {
                    required   : '<i class="fa fa-exclamation-circle"></i>url链接必须填写'
                },
                sort  : {
                    number   : '<i class="fa fa-exclamation-circle"></i>排序必须为数字'
                }
            }
        });
    });

    $("#fun").change(function(){
        var url = $(this).val();
        $("#url").val(url);
    });
</script>
